"""
@author: 江同学呀
@file: paginate_search_results.py
@date: 2025/1/20 21:33
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/paginate-search-results.html
"""
from typing import Dict, Union

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField


class Pit(_Base):
    """
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/point-in-time-api.html

    :param id_:
    :param keep_alive:
    """
    def __init__(self, id_: str, keep_alive: str):
        super().__init__()
        self._id: str = id_
        self._keep_alive: str = keep_alive
        return

    def _build(self) -> Dict:
        return {
            "id": self._id,
            "keep_alive": self._keep_alive
        }


class Slice(_Base):
    """
    切片

    :param id_:
    :param max_:
    :param field:
    """

    def __init__(self, id_: int, max_: int, field: Union[str, _BaseField]):
        super().__init__()
        self._id: int = id_
        self._max: int = max_
        self._field: Union[str, _BaseField] = field
        return

    def _build(self) -> Dict:
        _body: Dict = {
            "id": self._id,
            "max": self._max
        }
        if self._field:
            _body["field"] = self._field if isinstance(self._field, str) else self._field._field_name
        return _body

